<template>
	<view>
		<view class="fl jsp alc cell"  @click="upload">
			<text>头像</text>
			<u-avatar :src="$http+user.avatar"></u-avatar>
		</view>
		<view class="fl jsp alc cell">
			<text>昵称</text>
			<u-input border="none" input-align="right" v-model="user.nickName" clearable></u-input>
		</view>
		<view class="fl jsp alc cell" @click="show=true">
			<text>性别</text>
			<u-icon :name="user.sex==0?'man':'woman'" :color="user.sex==0?'blue':'pink'" size="20"></u-icon>
		</view>
		<view class="fl jsp alc cell">
			<text>邮箱</text>
			<u-input border="none" input-align="right" v-model="user.email" clearable></u-input>
		</view>
		
		<u-action-sheet :actions="list" @select="selectClick"  
		:show="show" cancelText="取消" @close="show=false"></u-action-sheet>
		
		<view class="c-box-nobg">
			<u-button type="primary" text="修改" ></u-button>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,getCurrentInstance
	} from 'vue';
	import {
		onLoad
	} from '@dcloudio/uni-app'
	const user = ref(uni.getStorageSync('user'))
	const show = ref(false)
	const {proxy} =getCurrentInstance()
	const list = ref([
		{
			name:'男',
			value:0
		},{
			name:"女",
			value:1
		}
	])
	const selectClick = (index)=>{
		user.value.sex = index.value
	}
	const upload =()=>{
		uni.chooseImage({
			complete(file) {
				let filePath = file.tempFilePaths[0]
				uni.uploadFile({
					url:proxy.$http+'/prod-api/common/upload',
					filePath,
					name:'file',
					header:{
						Authorization:uni.getStorageSync('token')
					},
					success(data) {
						uni.showToast({
							title:'上传头像成功'
						})
						let res=JSON.parse(data.data)
						user.value.avatar = '/prod-api/'+res.fileName
					}
				})
			}
		})
		
	}
	onLoad(() => {
		
	})
</script>

<style lang="scss">
.cell {
	height: 100rpx;
	border-bottom: 1rpx solid #ccc;
	padding: 10rpx;
}
</style>